package com.magicborrow.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.magicborrow.R;

/**
 * Created by ghost on 16/4/28.
 */
public class PeifuDialog extends Dialog {

    private EditText des;
    private EditText price;
    private Context context;

    private String msg;
    private OkListener okListener;


    public PeifuDialog(Context context) {
        super(context, R.style.msgDialog);
        this.context = context;
    }

    public void setOkListener(OkListener okListener){
        this.okListener = okListener;
    }

    public void setMsg(String msg) {
        this.msg = msg;
        ((TextView) findViewById(R.id.tv_msg)).setText(msg);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_peifu_dailog);
        setCanceledOnTouchOutside(true);
        des = (EditText)findViewById(R.id.tv_msg);
        price = (EditText)findViewById(R.id.price);
        ((TextView) findViewById(R.id.tv_msg)).setText(msg);
        findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String d = des.getText().toString();
                String p = price.getText().toString();
                if("".equals(d) || "".equals(p)){
                    Toast.makeText(context,"请填写完整的信息",Toast.LENGTH_SHORT).show();
                    return;
                }
                okListener.getContent(d,p);
            }
        });
        findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
    }

    public interface OkListener{
        void getContent(String dec,String price);
    }

}
